<template>
    <TopHeader></TopHeader>
    <TopSearch @search="goSearch"></TopSearch>
    <RouterView></RouterView>
    <Footer></Footer>
</template>

<script lang="ts" name="Index" setup>
import TopHeader from '@/components/header/index.vue';
import TopSearch from '@/components/header/search.vue';
import Footer from '@/components/footer/index.vue';
import {useRoute, useRouter} from 'vue-router'

const router = useRouter();
const route = useRoute();

function goSearch(keyword: string) {
    let query: any = {}
    //如果当前是搜索页，合并参数
    if (route.name === "search") {
        query = {...route.query}
    }
    keyword ? (query.keyword = keyword) : delete query.keyword;
    router.push({name: "search", query});
}
</script>

<style scoped></style>